
.PHONY : all clean rebuild ndiasm

BOOT_SRC := boot.asm
BOOT_OUT := boot.bin
BOOT_NDISASM := boot.txt

LOADER_SRC := loader.asm
LOADER_OUT := loader
LOADER_NDISASM := loader.txt

IMG := data.img
IMG_PATH := /mnt/hgfs

RM := rm -rf

all: $(IMG) $(BOOT_OUT) $(LOADER_OUT) ndisasm
	@echo "Build Success ==> D.T.OS"

$(IMG):
	bximage $@ -q fd -size=1.44

$(BOOT_OUT) : $(BOOT_SRC)
	nasm $^ -o $@
	dd if=$@ of=$(IMG) bs=512 count=1 conv=notrunc

$(LOADER_OUT) : $(LOADER_SRC)
	nasm $^ -o $@
	sudo mount -o loop $(IMG) $(IMG_PATH)
	sudo cp $@ $(IMG_PATH)/$@
	sudo umount $(IMG_PATH)

clean:
	$(RM) $(BOOT_OUT) $(LOADER_OUT) $(BOOT_NDISASM) $(LOADER_NDISASM)

rebuild:
	@$(MAKE) clean
	@$(MAKE) all

ndisasm: $(LOADER_OUT) $(BOOT_OUT)
	ndisasm -o 0x7c00 $(BOOT_OUT) > $(BOOT_NDISASM)
	ndisasm -o 0x9000 $(LOADER_OUT) > $(LOADER_NDISASM)
